<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>所有用户信息</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.4.9/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
        }
        #allUserInfoTable {
            width: 100%;
            max-width: 1200px;
            margin: 50px auto;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        #allUserInfoTable thead {
            background-color: #007bff;
            color: white;
        }
        #allUserInfoTable th, #allUserInfoTable td {
            text-align: center;
            vertical-align: middle;
            padding: 15px;
            border-color: #dee2e6;
        }
        #allUserInfoTable tbody tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        #allUserInfoTable tbody tr:hover {
            background-color: #ddd;
        }
        .container {
            padding: 200px;
        }
    </style>
</head>
<body>
    <div class="container">
        <table id="allUserInfoTable" class="table table-striped table-hover">
            <thead>
                <tr>
                    <th scope="col">ID</th>
                    <th scope="col">用户名</th>
                    <th scope="col">性别</th>
                    <th scope="col">年龄</th>
                    <th scope="col">班级ID</th>
                    <th scope="col">学生ID</th>
                    <th scope="col">专业</th>
                    <th scope="col">昵称</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
     <!--删除按钮-->
    <button type="button" class="btn btn-danger" id="deleteButton"></button>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            function fetchAllUserData() {
                $.ajax({
                    url: 'http://10.252.98.195:8888/UserProfile_select_all',
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify({}),
                    success: function(response) {
                        if (response.userinfo && response.userinfo.length > 0) {
                            var tbody = $('#allUserInfoTable tbody');
                            tbody.empty(); // 清空现有数据
                            response.userinfo.forEach(function(userInfo) {
                                var row = $('<tr>');
                                row.append($('<td>').text(userInfo.id));
                                row.append($('<td>').text(userInfo.user));
                                row.append($('<td>').text(userInfo.gender));
                                row.append($('<td>').text(userInfo.age));
                                row.append($('<td>').text(userInfo.classId));
                                row.append($('<td>').text(userInfo.stuId));
                                row.append($('<td>').text(userInfo.professional));
                                row.append($('<td>').text(userInfo.nickname));
                                tbody.append(row);
                            });
                        } else {
                            alert('没有找到用户信息');
                        }
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error('Error:', textStatus, errorThrown);
                    }
                });

                }

            // 初始加载数据
            fetchAllUserData();
            setInterval(fetchAllUserData, 5000); // 每5秒刷新一次
        });
    </script>
</body>
</html>
